package com.xuxu.blog.component;

import com.xuxu.blog.entity.bean.Video;
import com.xuxu.blog.service.impl.WebSocketServiceImpl;
import com.xuxu.blog.service.slef.FileService;
import com.xuxu.blog.vo.VoiceVO;
import com.xuxu.common.utils.R;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * @className: GetVoice
 * @author: Maxuxu
 * @date: 2022/8/26 10:36
 * @description: 获取语音消息
 */
@RestController
@RequestMapping("/blog")
@Slf4j
public class GetVoice {
    @Autowired
    private static String FILE_ADDRESS;
    @Autowired
    private WebSocketServiceImpl webSocketService;
    // private static UploadStrategyContext uploadStrategyContext;


    @Value("${file_address}")
    public void setFileAddress(String fileAddress) {
        FILE_ADDRESS = fileAddress;
    }
    /**
     * 保存语音信息
     *
     * @param voiceVO 语音信息
     * @return {@link R<String>} 语音地址
     */
    @ApiOperation(value = "上传语音")
    @PostMapping("/voice")
    public R sendVoice(VoiceVO voiceVO) {
        webSocketService.sendVoice(voiceVO);
        return R.ok("语音上传成功");
    }
    @PostMapping("/voice2")
    public R GetVoice2(MultipartFile file, String type, String nickname,Integer userId) throws IOException {
        Video video = FileService.DownLoad(file);
        video.setId(userId);
        log.info("传出的数据是：{}", video);
        return R.ok("发送成功").put("data",video);
    }
    @PostMapping("/sendVoice")
    public R sendVoice2(VoiceVO voice){
        return R.ok("成功响应");
    }

}
